/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package persistencia;


import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectInputStream;

/**
 *
 * @author Marcelo
 */
public class InputDAO extends DAO{
    private FileInputStream fis;
    private ObjectInputStream in;
    private File file;

    private void open() throws FileNotFoundException, IOException {
        file = new File(PATH);
        if(! file.exists()){
        	file.createNewFile();
        }
        fis = new FileInputStream(PATH);
        in = new ObjectInputStream(fis);
    }

    private void close() throws IOException {
        if (in != null) {
            in.close();
        }
    }
    
    @Override
    public Object read() throws IOException, ClassNotFoundException {
        Object o = null;
        open();
        if (in != null) {
            try { o = in.readObject();  } catch(IOException e) { e.printStackTrace(); };
            System.out.println("Class write: " + o.getClass().toString());
            close();
        }
        return o;
    }

}
